package jfc.core;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

/**
 *  @author Yann Le Gall
 *  ylegall@gmail.com
 *  Oct 25, 2009 8:43:52 PM
 */
public class Cell extends CardHolder {

    private Card card;

    public Cell(Point p) {
        super(p);
    }

    public void add(List<Card> list) {
        setCard(list.remove(0));
    }
    
    public int getTopValue() {
    	return (card != null)? card.getValue() : 0;
    }

    public void setCard(Card c) {
        card = c;
        card.setLocation(getLocation());
    }
    
    public void clear() {
        removeCard();
    }

    public List<Card> remove(int num) {
    	if(isEmpty()) return null;
    	ArrayList<Card> list = new ArrayList<Card>(1);
    	list.add(removeCard());
    	return list;
    	}
    
    public Card removeCard() {
        Card c = card;
        card = null;
        return c;
    }
    
    public Card peekTop() {
    	return card;
    }

    @Override
    public boolean isEmpty() {
        return card == null;
    }

    public void draw(Graphics2D g2) {
        if (card != null) {
            card.draw(g2);
        } else {
            Color c = g2.getColor();
            g2.setColor(Color.black);
            g2.drawRoundRect(x, y, width, height, 10, 10);
            g2.setColor(c);
        }
    }
}
